{include file="public_head" /}
<!-- upload -->
<link href="__STATIC__/css/uploads.css" rel="stylesheet">
<!-- upload_arr -->
<link href="__STATIC__/plupload/plupload.css" rel="stylesheet">
<!-- Select2 -->
<link href="__STATIC__/css/select/select2.min.css" rel="stylesheet">
<!-- sku -->
<link href="__STATIC__/css/sku.css" rel="stylesheet" type="text/css">

<body class="nav-md">

<div class="container body">

    <div class="main_container">

        {include file="public_sidebar,public_nav" /}
        <!-- page content -->
        <div class="right_col" role="main">
            <div class="">

                <div class="page-title">
                    <div class="title_left">

                    </div>
                </div>
                <div class="clearfix"></div>
                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">
                            <div class="x_title">
                                <h2>添加礼包
                                    <!--<small>different form elements</small>-->
                                </h2>
                                <ul class="nav navbar-right panel_toolbox">
                                    <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                    </li>
                                    <li><a class="close-link"><i class="fa fa-close"></i></a>
                                    </li>
                                </ul>
                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">
                                <br/>
                                <form class="form-horizontal form-label-left" enctype="multipart/form-data" action=""
                                      method="post" id="registerForm" onsubmit="return check()">

                                    <!--<div class="divider-dashed"></div>-->
                                    <!--<div class="form-group">-->
                                    <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">成 本 价：</label>-->
                                    <!--<div class="col-md-1 col-sm-6 col-xs-12">-->
                                    <!--<input type="text" placeholder="请输入成本价"-->
                                    <!--class="form-control col-md-7 col-xs-12" name="cost_price"-->
                                    <!--value="{$item.cost_price|default=''}"-->
                                    <!--&gt;-->
                                    <!--</div>-->
                                    <!--</div>-->


                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">礼包名称：</label>
                                        <div class="col-md-3 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="请填写礼包名称"
                                                   class="form-control col-md-7 col-xs-12" name="title"
                                                   value="{$item.title|default=''}" datatype="*" nullmsg="请填写礼包名称"
                                            >
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">售卖价格：</label>
                                        <div class="col-md-3 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="售卖价格"
                                                   class="form-control col-md-7 col-xs-12" name="sale_price"
                                                   value="{$item.sale_price|default=''}"  datatype="*" nullmsg="请填写售卖价格"
                                            >
                                        </div>
                                    </div>
                                    <!--<div class="form-group">-->
                                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">分销比(%)：</label>-->
                                        <!--<div class="col-md-3 col-sm-6 col-xs-12">-->
                                            <!--<input type="text" placeholder="请填写分销比"-->
                                                   <!--class="form-control col-md-7 col-xs-12" name="per"-->
                                                   <!--value="{$item.per|default=''}"  datatype="*" nullmsg="请填写分销比"-->
                                            <!--&gt;-->
                                        <!--</div>-->
                                    <!--</div>-->
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">原价：</label>
                                        <div class="col-md-3 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="原价"
                                                   class="form-control col-md-7 col-xs-12" name="origin_price"
                                                   value="{$item.origin_price|default=''}"
                                            >
                                        </div>
                                    </div>

                                    <div class="divider-dashed"></div>

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">添加数量：</label>
                                        <div class="col-md-1 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="请输入添加数量"
                                                   class="form-control col-md-7 col-xs-12" name="sycss"
                                                   value="{$item.sycss|default='1'}"
                                            >
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">前台销量：</label>
                                        <div class="col-md-1 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="前台销量"
                                                   class="form-control col-md-7 col-xs-12" name="goods_sale"
                                                   value="{$item.goods_sale|default=''}"
                                            >
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">促销区间：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="请选择时间区间"
                                                   class="form-control col-md-7 col-xs-12" name="interval_timer"
                                                   id="interval_timer"
                                                   {present name="$item.id"}
                                                   value="{$item.start_time} / {$item.end_time}"
                                                   {/present}
                                            datatype="*"
                                            nullmsg="请选择时间区间" errormsg="请选择时间区间！"
                                            >
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">礼包服务类次数：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <table class="table table-striped table-bordered table-hover">
                                                <thead>
                                                <th>服务分类</th>
                                                <th>服务内容</th>
                                                <th>服务次数</th>
                                                <th>服务期限</th>
                                                {if condition="session('role_id') eq 11 || session('role_id') eq 12 || session('role_id') eq 13" }
                                                {else/}
                                                <th>操作</th>
                                                {/if}
                                                </thead>
                                                <tbody id="fieldtr">
                                                {volist name="gift_count" id="list"}
                                                <tr>
                                                    <td>
                                                        <select name="single_id[]" class="form-control" tabindex="-1" onchange="cate(this.value,this)" >
                                                            {volist name=":json_decode($single_list,true)" id="li"}
                                                            <option value="{$li.id}" {eq name="$li.id" value="$list.single_id"}selected{/eq}>{:str_repeat('&nbsp',$li.level)}|-{$li.cat_name}</option>
                                                            {/volist}
                                                        </select>
                                                    </td>
                                                    <!--<script>-->
                                                    <!--$.ajax({-->
                                                    <!--url : '{:url("erjilei")}',-->
                                                    <!--data:{'id':id},-->
                                                    <!--dataType:'json',-->
                                                    <!--success:function(data){-->
                                                    <!--var str = [];-->
                                                    <!--console.log(data);-->
                                                    <!--str = '<select name="single_content[]" class="form-control" tabindex="-1">';-->
                                                    <!--$.each(data, function(k,v){-->
                                                    <!--str += '<option value="'+v.id+'">'+v.name+'</option>';-->
                                                    <!--});-->
                                                    <!--str += '</select>';-->
                                                    <!--$('#assignor_id').html(str);-->
                                                    <!--console.log(str);-->
                                                    <!--}-->
                                                    <!--});-->
                                                    <!--</script>-->
                                                    <td>
                                                        <select name="single_content[]" class="form-control" tabindex="-1" >
                                                            {volist name="list.two_array" id="li"}
                                                            <option value="{$li.id}" {eq name="$li.id" value="$list.single_content"}selected{/eq}>|-{$li.cat_name}</option>
                                                            {/volist}
                                                        </select>
                                                    </td>
                                                    <td><input type="text" name="gift_count[]" style="width:100px;" value="{$list.gift_count}"  /></td>
                                                    <td><input type="text" name="day[]" style="width:100px;" value="{$list.day}"  /></td>
                                                    {if condition="session('role_id') eq 11 || session('role_id') eq 12 || session('role_id') eq 13" }
                                                    {else/}
                                                    <td><a href="javascript:;" onclick="delThis($(this),{$list.id})" >删除</a></td>
                                                    {/if}
                                                </tr>
                                                {/volist}
                                                </tbody>
                                                {if condition="session('role_id') eq 11 || session('role_id') eq 12 || session('role_id') eq 13" }
                                                {else/}
                                                <tbody align="right">
                                                <tr>
                                                    <td colspan="5"><a href="javascript:;" class="addNewTr" title="新增一条" >新增一条</a></td>
                                                </tr>
                                                </tbody>
                                                {/if}

                                            </table>
                                        </div>
                                    </div>

                                    <div class="abc" style="display: none;"><li></li><li><input type="text" data_type="stock"/></li></div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">图片上传【720*372】:</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <div id="imgdiv">
                                                <img id="imgShow" src="__PUBLIC__/{$item.single_pic|default=''}"
                                                     width="200" height="190" onerror="this.src='__STATIC__/images/default.png'"
                                                />
                                            </div>
                                            <div class="uploader white">
                                                <input type="text" class="filename" name="single_pic"
                                                       value="{$item.single_pic|default=''}" readonly/>
                                                <input type="button" name="file" class="button" value="上传..."/>
                                                <input type="file" id="up_img" name="single_pic"
                                                       value='{$item.single_pic|default=""}'  />
                                            </div>
                                        </div>
                                    </div>

                                    <div class="divider-dashed"></div>

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">上传组图：【720*372】</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">

                                            <div class="uploader white">
                                                <input type="button" id="logo_upload_btn" class="button" value="批量上传"/>
                                            </div>

                                            <div id="logo_upload_area" style='width:80%'>
                                                <div id='photos_area' class="photos_area clearfix">

                                                    {if condition="($Request.action eq 'update') && ($item.multi_pic neq 'N;')"}
                                                    {foreach :unserialize($item['multi_pic']) as $picValue}
                                                    <div class="item">
                                                        <input type="hidden" name="picArr[]" value="{$picValue}">
                                                        <img src="__PUBLIC__/{$picValue}" width="100px" height="100px">
                                                        <div class="operate">
                                                            <i class="toleft">左移</i>
                                                            <i class="toright">右移</i>
                                                            <i class="del">删除</i>
                                                        </div>
                                                    </div>
                                                    {/foreach}
                                                    {/if}

                                                </div>
                                                <div class="alert alert-success" role="alert"
                                                     style="margin:10px 0;"><strong><span
                                                        class="glyphicon glyphicon-flag"></span>点击批量上传按钮上传多张图片:</strong>&nbsp;&nbsp;单张图片大小不超过500KB,格式为jpg,png,gif,jpeg
                                                </div>

                                            </div>

                                        </div>
                                    </div>

                                    <div class="divider-dashed"></div>

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">商品内容：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <textarea type="text/plain" style=" height: 300px; width: 100%; " id="containers"
                                                      name="content"
                                                      placeholder="请输入商品内容">
                                                {$item.content|default=''}
                                            </textarea>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">购买须知：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <textarea type="text/plain" style=" height: 300px; width: 100%" id="containerss"
                                                      name="buy_must_know"
                                                      placeholder="请输入购买须知内容">
                                                {$item.buy_must_know|default=''}
                                            </textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">排序：</label>
                                        <div class="col-md-3 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="请填写排序"
                                                   class="form-control col-md-7 col-xs-12" name="sort"
                                                   value="{$item.sort|default='0'}" datatype="*" nullmsg="请填写排序"
                                            >
                                        </div>
                                    </div>
                                    {include file="auding_status" /}
                                    <div class="divider-dashed"></div>



                                    <div class="ln_solid"></div>

                                    <div class="form-group">
                                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                                            {present name="$item.id"}
                                            <input type="hidden" name="id" value="{$item.id}">
                                            {/present}
                                            <input type="hidden" name="member_id" value="{:session('shop_id')}"/>
                                            <button type="submit" class="btn btn-primary">提交</button>
                                            <a type="reset" class="btn btn-success" onclick="history.go(-1)">返回</a>
                                        </div>
                                    </div>

                                </form>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
            <!-- /page content -->

        </div>

    </div>
</div>

{include file="public_foot" /}
<!-- upload_arr -->
<script src="__STATIC__/js/upload.photos.js"></script>
<script type="text/javascript" src="__STATIC__/plupload/plupload.full.min.js"></script>
<!-- Times -->
<script src='__STATIC__/js/datepicker/WdatePicker.js'></script>
<!-- validform -->
<script src="__STATIC__/js/Validform_v5.3.2_min.js"></script>
<script src="__STATIC__/js/layer.js"></script>
<!-- select -->
<script src="__STATIC__/js/select/select2.full.min.js"></script>
<!-- upload -->
<script type="text/javascript" src="__STATIC__/js/uploadPreview.js"></script>

<!-- ueditor -->
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">



</script>
<script>


    // validform
    $(function () {

        $.Tipmsg.r = null;

        var showmsg = function (msg) {
            //假定你的店铺商品提示方法为showmsg， 在方法里可以接收参数msg，当然也可以接收到o及cssctl;
            alert(msg);
        }
        $("#registerForm").Validform({
            tiptype: function (msg) {
                layer.msg(msg);
            },
            tipSweep: true
        });

        // 实例化编辑器
        var ue = UE.getEditor('containers');
        var ue = UE.getEditor('containerss');

        // upload
        new uploadPreview({UpBtn: "up_img", DivShow: "imgdiv", ImgShow: "imgShow"});

        // select2
        $(".select2_single").select2({
            placeholder: "请选择分类",
            allowClear: true
        });

        // 组图排序 删除图片
        $(".toleft").live("click", function () {
            var item = $(this).parent().parent(".item");
            var item_left = item.prev(".item");
            if ($("#photos_area").children(".item").length >= 2) {
                if (item_left.length == 0) {
                    item.insertAfter($("#photos_area").children(".item:last"));
                } else {
                    item.insertBefore(item_left);
                }
            }

        })

        $(".toright").live("click", function () {
            var item = $(this).parent().parent(".item");
            var item_right = item.next(".item");
            if ($("#photos_area").children(".item").length >= 2) {
                if (item_right.length == 0) {
                    item.insertBefore($("#photos_area").children(".item:first"));
                } else {
                    item.insertAfter(item_right);
                }
            }
        })

        $(".del").live("click", function () {
            $(this).parent().parent(".item").remove();
        })

        $(":radio").click(function () {

            if (this.checked) {
                if ($(this).attr("id") == "freight_type_1") {
                    $("#immobilization").show();
                    $("#template").hide();
                }else{
                    $("#immobilization").hide();
                    $("#template").hide();
                }
            }
        });
    });

    // 组图上传
    var uploader = new plupload.Uploader({
        runtimes: 'html5,flash,silverlight,html4',
        browse_button: 'logo_upload_btn',
        url: "/index.php/client/shop_goods/uploadarr.html",
        flash_swf_url: '__STATIC__/plupload/Moxie.swf',
        silverlight_xap_url: '__STATIC__/plupload/Moxie.xap',
        filters: {
            max_file_size: '500kb',
            mime_types: [
                {title: "files", extensions: "jpg,png,gif,jpeg"}
            ]
        },
        multi_selection: true,
        init: {
            FilesAdded: function (up, files) {
                $("#btn_submit").attr("disabled", "disabled").addClass("disabled").val("正在上传...");
                var item = '';
                plupload.each(files, function (file) { //遍历文件
                    item += "<div class='item' id='" + file['id'] + "'><div class='progress'><span class='bar'></span><span class='percent'>0%</span></div></div>";
                });
                $("#photos_area").append(item);
                uploader.start();
            },
            UploadProgress: function (up, file) { //上传中，显示进度条
                var percent = file.percent;
                $("#" + file.id).find('.bar').css({"width": percent + "%"});
                $("#" + file.id).find(".percent").text(percent + "%");
            },
            FileUploaded: function (up, file, info) {

                var data = eval("(" + info.response + ")");

                $("#" + file.id).html("<input type='hidden' name='picArr[]' value='" + data.src + "'><img src='__PUBLIC__/" + data.src + "' alt='" + data.name + "' width='100px' height='100px'><div class='operate'><i class='toleft'>左移</i><i class='toright'>右移</i><i class='del'>删除</i></div>")
                $("#btn_submit").removeAttr("disabled").removeClass("disabled").val("提 交");
                if (data.error != 0) {
                    layer.msg(data.error);
                }
            },
            Error: function (up, err) {
                layer.msg(err.message);
                $("#btn_submit").removeAttr("disabled").removeClass("disabled").val("提 交");
            }
        }
    });
    uploader.init();


        function delThisTr(trobj)
        {
            trobj.parent().parent().remove();
        }

        function delThis(trobj,id)
        {
            if(confirm('确认删除？')){
                $.ajax({
                    url : '{:url("gift_count")}',
                    data:{'id':id},
                    dataType:'html',
                    success:function(data){
                        if(data == 'true'){
                            layer.msg('删除成功');
                            trobj.parent().parent().remove();
                        }else{
                            layer.msg('网络繁忙,请重试');
                        }
                    }
                });
            }
        }
    var single_list = {$single_list};
    var default_cotent = {$default_content};
    console.log(default_cotent);
    var ss = [];

    //var disabled = "disabled";
    $.each(single_list, function(k,v){
        var ds;
        if(v.level == 444){
            ds = 'disabled="disabled"';
        }else{
            ds = '';
        }
        ss += '<option value="'+v.id+'"'+ds+'>'+'&nbsp&nbsp'.repeat(v.level)+'|-'+v.cat_name+'</option>';
    });
    var sss = [];
    $.each(default_cotent, function(k,v){
        var ds;
        if(v.level == 444){
            ds = 'disabled="disabled"';
        }else{
            ds = '';
        }
        sss += '<option value="'+v.id+'"'+ds+'>'+'|-'+v.cat_name+'</option>';
    });

    $(".addNewTr").click(function(){
        str = '<tr><td><select name="single_id[]" onchange="cate(this.value,this)" class="form-control" tabindex="-1">' + ss +
            '</select></td>' +
            '<td><select name="single_content[]" class="form-control" tabindex="-1">' + sss +
        '</select></td>' +
            '<td><input type="text" name="gift_count[]" style="width:100px;" /></td>' +
            '<td><input type="text" name="day[]" style="width:100px;" /></td>' +
        '<td><a href="javascript:;" onclick="delThisTr($(this))">删除</a></td></tr>';
        $("#fieldtr").append(str);
    });

    function cate(vv,t) {
        $.ajax({
            url : '{:url("single2")}',
            data:{'id':vv},
            dataType:'html',
            success:function(data){
                var data = JSON.parse(data);
              var s2;
                $.each(data, function(k,v){
                    s2 += '<option value="'+v.id+'">'+'|-'+v.cat_name+'</option>';
                });
                console.log(s2);
              var str = '<select name="single_content[]" class="form-control" tabindex="-1">'+ s2
                      +
                  '</select>';

              $(t).parent().next().html(str);
            }
        });
    }





</script>
<!-- daterangepicker -->
<script src="__STATIC__/js/datepicker/daterangepicker.js"></script>
<script type="text/javascript">
    $('#interval_timer').daterangepicker(null,
        function(start, end, label) {
            console.log(start.toISOString(), end.toISOString(), label);
        });
    var str = '<a href="http://www.baidu.com">链接111111111</a> ';
    var reg1 = /href=\"(.+)\"/g;
    var reg2 = /\">(.+)<\/a>/g;
    var retVal1 = reg1.exec(str);
    var retVal2 = reg2.exec(str);
    //alert(retVal1[1]);
    //alert(retVal2[1]);
</script>
<script src="__STATIC__/js/sku.js"></script>
</body>

</html>
